/* dosy_adsu.gp
A 2D dataset is produced by subtracting the DOSY-SHARPER spectrum of the solvent from the DOSY-SHARPER of a sample 
- start in the EXPNO containing the DOSY data of the sample (A). 
- input the EXPNO containing the DOSY data of solvent only (B).
- program asks for the EXPNO for the A-B data set. 
- performs xf2 and expect the user to proceed with additional commands manually.
- can take initial data pre or post DOSY transform, before or after the removal of the imaginary component (if applicable).

George Peat
05 October 2022
george.peat@ed.ac.uk
*/

#include <inc/sysutil>
#include <inc/exptUtil>

int     first,iexpno;
float f1phc0;
//double  swp;
char buffer[1024]; //this buffer is for the XCMD string for splitting, may need memory optimisation

//get current data
GETCURDATA 

//define our new expnos for the split data
first=expno;
iexpno = expno+1000;
expno2 = expno+1;
GETINT("Enter the EXPNO of the solvent dataset to be subtracted", expno2)
GETINT("Enter the EXPNO for the final cleaned spectrum", iexpno)
if (first==iexpno)
	STOPMSG("program aborted\nYou don't want to overwrite the original dataset")

//Open main data set and process

DATASET(name, expno, 1, disk, user)
VIEWDATA_SAMEWIN
XF2;

// store paramters for subtraction

STOREPAR("ALPHA",1.0);
STOREPAR("GAMMA",-1.0);

WRA(iexpno)
WRPA(name, iexpno, procno, disk, user)

DATASET(name, iexpno, 1, disk, user)
VIEWDATA_SAMEWIN
XF2;

// Perform subtraction and store data in new expno

DATASET2(name, expno2, procno, disk, user);
ADDSER;

DATASET(name, iexpno, 1, disk, user)
VIEWDATA_SAMEWIN
XF2;

snprintf(buffer, sizeof(buffer), "Processing complete\nSee expno  %d for results. ", iexpno);	
QUITMSG(buffer);

